<template>
	<view>
		<textarea class="title" placeholder-style="color:#999999" placeholder="请输入标题（5~30个字）" maxlength="30" @input="titleInput"></textarea>
		<textarea class="cont" placeholder-style="color:#999999" placeholder="请输入正文" @input="descInput"></textarea>
		<view class="bottom" @click="releaseWish">发布愿望</view>
	</view>
</template>

<script>
	export default{
		data() {
			return {
				remnant: 0, //当前标题的字数
				apply_text: '' , //当前标题的内容
				content: '' ,//当前正文的内容
				sign:''
			}
		},
		onLoad() {
			this.$zapi.apiPost('user/App/getsign').then(res=>{
						if(res.data.code==200){
							this.sign=res.data.data.sign;
						}
					});
		},
		methods: {
			/* 发布愿望 */
			releaseWish() {
				this.content = this.content.replace(/&lt;/g, '<').replace(/&gt;/g, '>');
				var data = {
					title: this.apply_text,
					content: this.content,
					sign:this.sign
				}
				if (this.remnant >= 30) {
					uni.showToast({
						title: '最多只能输入30个字',
						icon: 'none'
					})
				} else if (this.remnant < 5) {
					uni.showToast({
						title: '最少需要输入5个字',
						icon: 'none'
					})
				}else{
				this.$zapi.apiPost('user/newarticle.Wishlist/issueWish',data).then(res=>{
					uni.showToast({
						title: res.data.msg,
						icon: 'none'
					})
					if(res.data.code == 200){
						setTimeout(function(){
							uni.navigateBack({
								delta: 1
							})
						},1000)
					}
				})}
			},
			/* 获取标题的长度及内容 */
			titleInput(e) {
				this.remnant = e.detail.cursor;
				this.apply_text = e.detail.value;
			},
			descInput(e) {
				this.content = e.detail.value;
			}
		},
	}
</script>

<style>
	page{
		background: #FFFFFF;
	}
	.title{
		color: #333333;
		font-size: 38upx;
		width: calc(100% - 60upx);
		background-color: #FFFFFF;
		padding: 30upx;
		height: 100upx;
	}
	.cont{
		color: #333333;
		font-size: 32upx;
		width: calc(100% - 60upx);
		background-color: #FFFFFF;
		padding: 30upx;
		border-top: 20upx solid #FAFAFA;
	}
	/* 底部 */
	.bottom{
		position: fixed;
		left: 30upx;
		bottom: 30upx;
		width: 690upx;
		background: #FF9900;
		border-radius: 8upx;
		height: 80upx;
		line-height: 80upx;
		text-align: center;
		color: #FFFFFF;
		z-index: 1;
	}
</style>
